home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR10 / YICN23.ZIP / DOC / PLATFORM.DOC < prev    next >
Text File  |  1993-03-06  |  5KB  |  162 lines

  1. Platform games like Jill of the Jungle and the Commander Keen series have
  2. been very successful.  However, they all follow some similar patterns which
  3. can be put together in a library.  The platform game routines here should
  4. ease development of such a game considerably.
  5.  
  6. #ifndef PLATFORM_H
  7. #define PLATFORM_H
  8.  
  9. #include "factor.h"
  10.  
  11. #define FLOORHEIGHT 40
  12.  
  13. #define FLOOR 0x01 //floor bit.
  14.  
  15. class platformBeast : public factor
  16. {
  17. public:
  18.   int xMomentum, yMomentum, gravity, moveIncrement, jumpIncrement;
  19.   int hitPoints, alignment, damage;
  20.   platformBeast() {xMomentum = alignment = damage = yMomentum = hitPoints= moveIncrement = jumpIncrement = 0;
  21.                    gravity = 2;};
  22.   virtual void advance(void);
  23.   void die(void);
  24.   enum command {goLeft, goRight, jump};
  25.   int targetTerrain() {return mymap->mapData[(mapX*mymap->squareWidth + squareX + xMomentum) / (mymap->squareWidth)]
  26.                                              [(mapY*mymap->squareWidth + squareY + yMomentum) / (mymap->squareWidth)].myTerrainType;};
  27.   void go(command myCommand);
  28. };
  29.  
  30. class player;
  31.  
  32. class missile : public platformBeast
  33. {
  34. public:
  35.   int range;
  36.   int missileNumber;
  37.   int damage;
  38.   player * owningPlayer;
  39.   missile(void) {gravity = 0; range = missileNumber = damage = 0; owningPlayer = NULL;}
  40.   virtual void advance(void);
  41. };
  42.  
  43. class player : public platformBeast
  44. {
  45. public:
  46.   missile * myMissiles[5];
  47.   int numMissiles; //number of missiles he can fire
  48.   int missileType;
  49.   player(void) : platformBeast() {myMissiles[0] = myMissiles[1] = myMissiles[2] = myMissiles[3]=
  50.                                   myMissiles[4] = NULL;};
  51.   void fireMissile(void);
  52.   virtual missile * missileGenerator(int missileType) {return NULL;};
  53.   int hitWithMissile(platformBeast * target);
  54. };
  55.  
  56. class crawler : public platformBeast
  57. {
  58. public:
  59.   virtual void advance(void);
  60. };
  61.  
  62. #endif
  63.  
  64. #ifndef PLATFORM_H
  65. #define PLATFORM_H
  66.  
  67. #include "factor.h"
  68.  
  69. #define FLOORHEIGHT 40
  70.  
  71. #define FLOOR 0x01 //floor bit.
  72.  
  73. class platformBeast : public factor
  74. This is the generic object in the platform game, be it monster, player, or
  75. whatever.
  76. {
  77. public:
  78.   int xMomentum, yMomentum, gravity, moveIncrement, jumpIncrement;
  79. These contain the current situation of the platformBeast.  Different beasts
  80. can have different gravities (even reverse gravities).  MoveIncrement and
  81. jumpIncrement affect the speed of the character's movement.
  82.  
  83.   int hitPoints, alignment, damage;
  84. Hit points have to do with life.  Alignment is used if you want platform
  85. beasts that will help the player.  Damage is how much damage a creature causes
  86. if it hits one of a different alignment.
  87.  
  88.   platformBeast() {xMomentum = alignment = damage = yMomentum = hitPoints= moveIncrement = jumpIncrement = 0;
  89.                    gravity = 2;};
  90. Constructor.
  91.  
  92.   virtual void advance(void);
  93. Advances the beast.
  94.  
  95.   void die(void);
  96. Kills the beast.
  97.  
  98.   enum command {goLeft, goRight, jump};
  99. Commands you can give to a beast.
  100.  
  101.   int targetTerrain() {return mymap->mapData[(mapX*mymap->squareWidth + squareX + xMomentum) / (mymap->squareWidth)]
  102.                                              [(mapY*mymap->squareWidth + squareY + yMomentum) / (mymap->squareWidth)].myTerrainType;};
  103. Returns the type of terrain the beast is about to enter.  Handy for checking
  104. if critters are about to fall off a ledge.
  105.  
  106.   void go(command myCommand);
  107. Gives a command to a platformBeast.
  108. };
  109.  
  110. class player;
  111.  
  112. class missile : public platformBeast
  113. {
  114. public:
  115.   int range;
  116. How many frames the missile will be active.
  117.  
  118.   int missileNumber;
  119. # of the missile in the player's inventory.
  120.  
  121.   int damage;
  122. Damage caused by the missile.
  123.  
  124.   player * owningPlayer;
  125. Who owns the missile?
  126.  
  127.   missile(void) {gravity = 0; range = missileNumber = damage = 0; owningPlayer = NULL;}
  128.   virtual void advance(void);
  129. Constructor and advancer.
  130. };
  131.  
  132. class player : public platformBeast
  133. {
  134. public:
  135.   missile * myMissiles[5];
  136. Array of missiles.
  137.  
  138.   int numMissiles; //number of missiles he can fire
  139.   int missileType; //type of missile
  140.  
  141.   player(void) : platformBeast() {myMissiles[0] = myMissiles[1] = myMissiles[2] = myMissiles[3]=
  142.                                   myMissiles[4] = NULL;};
  143. Constructor.
  144.  
  145.   void fireMissile(void);
  146. Hurm.
  147.  
  148.   virtual missile * missileGenerator(int missileType) {return NULL;};
  149. Produces a missile of the appropriate type.
  150.  
  151.   int hitWithMissile(platformBeast * target);
  152. Did any missiles hit the beast?
  153. };
  154.  
  155. class crawler : public platformBeast
  156. Crawls back and forth on a ledge until it reaches the edge.  Not much to it.
  157. {
  158. public:
  159.   virtual void advance(void);
  160. };
  161.  
  162. #endif